/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package filter;

import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
/**
 *
 * @author Administrator
 */
public class sessionFilter implements Filter {
    
    
 

    /**
     *
     * @param request The servlet request we are processing
     * @param response The servlet response we are creating
     * @param chain The filter chain we are processing
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet error occurs
     */
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain)
            throws IOException, ServletException {
        if(request.getParameter("user")!=null){
      String u=request.getParameter("user");
               ((HttpServletRequest) request).getSession().setAttribute("user", u);
       }
            String user="";
              if (((HttpServletRequest) request).getSession().getAttribute("user") != null) {
       user=(String)(((HttpServletRequest) request).getSession().getAttribute("user"));}
              System.out.println(user);
     // int item = Integer.parseInt(request.getParameter("i"));
       // HttpServletResponse wrappedResponse = (HttpServletResponse) response;
      
     //  ServletResponse response1=(ServletResponse)wrappedResponse;
       response.setContentType("text/html;charset=gb2312");
        //response.setHeader("Access-Control-Allow-Origin", "*");
       
   
            chain.doFilter(request, response);
       
        }
        
       
   

    /**
     * Destroy method for this filter
     */
    public void destroy() {        
    }

    /**
     * Init method for this filter
     */
    public void init(FilterConfig filterConfig) {        
        
    }

   

    
}
